package com.cn.serverline.lineicp.productionLine.factory;

import com.cn.serverline.lineicp.productionLine.constants.ProcessMaterialsConstant;
import com.cn.serverline.lineicp.productionLine.handler.AuxiliaryMaterialsHandler;
import com.cn.serverline.lineicp.productionLine.handler.ConsumablesHandler;
import com.cn.serverline.lineicp.productionLine.handler.MaterialHandler;
import com.cn.serverline.lineicp.productionLine.handler.SparePartsHandler;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * MaterialHandlerFactory 工厂类，根据物料类型获取相应的处理器实例
 *
 * @author Gmr
 * @since 2024/8/1
 */
@Component
public class MaterialHandlerFactory {

	@Resource
	private AuxiliaryMaterialsHandler auxiliaryMaterialsHandler;

	@Resource
	private SparePartsHandler sparePartsHandler;

	@Resource
	private ConsumablesHandler consumablesHandler;

	private static final Map<String, MaterialHandler> HANDLERS = new HashMap<>();

	@PostConstruct
	public void init() {
		HANDLERS.put(ProcessMaterialsConstant.AUXILIARY_MATERIALS, auxiliaryMaterialsHandler);
		HANDLERS.put(ProcessMaterialsConstant.SPARE_PARTS, sparePartsHandler);
		HANDLERS.put(ProcessMaterialsConstant.CONSUMABLES, consumablesHandler);
	}

	// 根据物料类型获取相应的处理器实例
	public static MaterialHandler getHandler(String materialType) {
		return HANDLERS.get(materialType);
	}
}
